package net.xinqushi.design.singleton;

import org.apache.tomcat.util.net.NioSelectorPool;

import java.io.IOException;
import java.nio.channels.Selector;

/**
 * @author xjie
 * @description 饿汉式单例模式实现方式在类加载到内存的时候，就创建好对象了
 * @see NioSelectorPool
 */
public class NoLazySingleton {
    private static Selector SHARED_SELECTOR;

    static {
        try {
            SHARED_SELECTOR = Selector.open();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Selector getSharedSelector() {
        //饿汉单例
        return  SHARED_SELECTOR;
    }
}
